<?php
if(!defined('ADMIN')){
	exit('Access Denied');
}

if(isset($_POST['sub']) && $_POST['sub']==1){
	$name=$_POST['username'];
	$pwd=$_POST['Password'];
	$yzm=$_POST['yzm'];
	if (reg_captcha($yzm)==0){
	    jump('index.php','验证码错误！');
	}
    if(empty($pwd)){
        jump('index.php','账号密码错误！');
    }
    
    $admin=$ezhand->select('adminuser','*','adminname="'.$name.'" and adminpass="'.deep_jm($pwd).'"');

    if(empty($admin)){
          
        jump('index.php','账号密码错误！');
    }
	if($admin['id']>0){
		$data = array (
	        array (
		        'f' => 'lastlogintime',
		        'e' => '=',
		        'v' => $admin['logintime']
	        ),
			array (
		        'f' => 'lastloginip',
		        'e' => '=',
		        'v' => $admin['loginip']
	        ),
			array (
		        'f' => 'loginnum',
		        'e' => '+',
		        'v' => 1
	        ),
			array (
		        'f' => 'logintime',
		        'e' => '=',
		        'v' => TIME
	        ),
			array (
		        'f' => 'loginip',
		        'e' => '=',
		        'v' => get_client_ip()
	        ),
        );
		$ezhand->update('adminuser',$data,'id='.$admin['id']);
		$_SESSION['EZ_Admin']['name']=$admin['adminname'];
		$_SESSION['EZ_Admin']['id']=$admin['id'];
		$_SESSION['EZ_Admin']['role_id']=$admin['role'];
                $_SESSION['EZ_Admin']['shop_id']=$admin['shop_id'];
        
		$cookie = array();
		$cookie['uid'] = $admin['id'];
		$cookie['lastvisit'] = $admin['lastlogintime'];
		$cookie['lastip'] = $admin['lastloginip'];
		$cookie['hash'] = md5($admin['adminpass'] . $admin['adminname']);
		$session = base64_encode(json_encode($cookie));
        $_SESSION[$config['cookie']['pre'].'__session']=$session;        
		
		//$menu_id=$ezhand->select('menu as a,menu_access as b','a.id','a.`mod`="webset" and a.`act`="center" and a.id=b.menu_id and b.role_id="'.$admin['role'].'"');
		//if(!$menu_id){
		//    $menu=$ezhand->select('menu as a,menu_access as b','a.`mod`,a.`act`','a.id=b.menu_id and b.role_id="'.$admin['role'].'" and hide=0');
		//	$array=array('go_mod'=>$menu['mod'],'go_act'=>$menu['act']);
		//}
		//else{
		    $array=array('go_mod'=>'webset','go_act'=>'center');
		//}
        //print_r($array);
	    jump(u('index','index',$array));
	}
	else{
	    jump('index.php','账号密码错误！');
	}
}
?>